import { Page } from "puppeteer";

export const loadCookiesFromFile = async (page: Page, filePath: String) => {
  try {
    // Reading cookies from the specified file
    const fs = require("fs");
    const cookiesJson = fs.readFileSync(filePath, "utf-8");
    const cookies = JSON.parse(cookiesJson);

    // Setting the cookies in the current page
    await page.setCookie(...cookies);
    // Cookies have been loaded successfully
    return true;
  } catch (error) {
    // An error occurred while loading cookies
    console.error("Error loading cookies:", error);
    return false;
  }
};